package com.gtlab1207.br_awareness.services;

import com.gtlab1207.br_awareness.models.domain.LogHost;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TimerTask;

import static com.gtlab1207.br_awareness.common.Constant.SYSTEM_LOG;

/**
 * 自定义定时器类
 */
//一定要加上这个注解 不然无法注入service对象
@Component
public class LogRecordWriteTimerTask extends TimerTask {
    @Autowired
    private LogRecordService logRecordService;
    @Autowired
    private LogHostService logHostService;

    @Override
    public void run() {
        //写入前删除大于七天的数据
        logRecordService.deleteLogRecord();
        // 在这里执行写日志操作
        List<LogHost> logHostList = logHostService.getActivatedLogHost();
        if (logHostList != null && logHostList.size() > 0) {
            for (LogHost i : logHostList) {
                logHostService.updateLastScanTime(i.getId());
                logRecordService.writeSuricataLog(i);
                logRecordService.writeSecurityLog(i);
                logRecordService.writeSystemLog(i);
            }
        }
    }
}
